package com.ruoyi.web.controller.ring;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ring.domain.RingSportRecord;
import com.ruoyi.ring.service.IRingSportDetailService;
import com.ruoyi.ring.service.IRingSportRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 运动Controller
 * 
 * @author liuwp
 * @date 2025-08-07
 */
@RestController
@RequestMapping("/ring/ring_sport_record")
public class RingSportRecordController extends BaseController
{
    @Autowired
    private IRingSportRecordService ringSportRecordService;
    @Autowired
    private IRingSportDetailService ringSportDetailService;

    /**
     * 查询运动列表
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_sport_record:list')")
    @GetMapping("/list")
    public TableDataInfo list(RingSportRecord ringSportRecord)
    {
        startPage();
        List<RingSportRecord> list = ringSportRecordService.selectRingSportRecordList(ringSportRecord);
        return getDataTable(list);
    }

    /**
     * 导出运动列表
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_sport_record:export')")
    @Log(title = "运动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RingSportRecord ringSportRecord)
    {
        List<RingSportRecord> list = ringSportRecordService.selectRingSportRecordList(ringSportRecord);
        ExcelUtil<RingSportRecord> util = new ExcelUtil<RingSportRecord>(RingSportRecord.class);
        util.exportExcel(response, list, "运动数据");
    }

    /**
     * 获取运动详细信息
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_sport_record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ringSportRecordService.selectRingSportRecordById(id));
    }

    /**
     * 新增运动
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_sport_record:add')")
    @Log(title = "运动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RingSportRecord ringSportRecord)
    {
        return toAjax(ringSportRecordService.insertRingSportRecord(ringSportRecord));
    }

    /**
     * 修改运动
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_sport_record:edit')")
    @Log(title = "运动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RingSportRecord ringSportRecord)
    {
        return toAjax(ringSportRecordService.updateRingSportRecord(ringSportRecord));
    }

    /**
     * 删除运动
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_sport_record:remove')")
    @Log(title = "运动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ringSportRecordService.deleteRingSportRecordByIds(ids));
    }

}
